<template>
  <div id="user">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
  <el-card class="box-card">
    <el-row :gutter="20">
      <el-col :span="8">
        <el-input placeholder="请输入内容">
          <template #append>
            <el-button icon="el-icon-search"></el-button>
          </template>
        </el-input>
      </el-col>
      <el-col :span="4">
        <el-button type="primary">添加用户</el-button>
      </el-col>
    </el-row>

    <el-table :data="userList" style="width: 100%">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column
        prop="username"
        label="用户名"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="role_name"
        label="角色"
        width="180"
      ></el-table-column>
      <el-table-column prop="email" label="邮箱" width="180"></el-table-column>
      <el-table-column
        prop="mobile"
        label="手机号"
        width="180"
      ></el-table-column>
      <el-table-column
        prop="mg_state"
        label="状态"
        width="180"
      >
        <template v-slot:default="scope">
          {{scope.row}}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180"></el-table-column>
    </el-table>
  </el-card>
</template>

<script>
export default {
  name: 'User',
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 2,
      },
      total: 0,
      userList: [
        { username: '', role_name: '', email: '', mobile: '', mg_state: true },
      ],
    }
  },
  created() {
    this.getUserList()
  },
  methods: {
    async getUserList() {
      const { data: res } = await this.$http.get('users', {
        params: this.queryInfo,
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取用户数据失败！')
      }
      this.userList = res.data.users
      this.total = res.data.total
      console.log(this.userList)
    },
  },
}
</script>

<style>
</style>
